package com.tff.gmall.redisson.controller;

import com.tff.gmall.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

/**
 * @author Fafa Tuo
 * @version 1.0
 * @date 2021/5/12 23:19
 */
@Controller
public class RedissonController {

    @Autowired
    private RedissonClient redissonClient;

    RedisUtil redisUtil = new RedisUtil();


    @RequestMapping(value = "/index")
    @ResponseBody
    public String index(){

        Jedis jedis = redisUtil.getRedis();
        String v = jedis.get("k");
        if(StringUtils.isBlank(v)){
            v = "1";
        }
        System.out.println("-> "+v);
        jedis.set("k",(Integer.parseInt(v)+1)+"");
        jedis.close();
       // RLock lock = redissonClient.getLock("tuofafa");
        return "success";
    }

}
